package com.neuedu.io;

import java.io.*;

public class Read_writeDemo {
    public static void main(String[] args) {

        File  file1 = new File("d://a.txt");
        File  file2 = new File("d://c.txt");

        if(!file2.exists()){
            try {
                file2.createNewFile();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        Reader   rd ;
        Writer   wt;
        try {
            rd= new FileReader(file1);
            wt = new FileWriter(file2);
            int len = -1;
////////////////11111111111111111111
//            while (( len = rd.read())!=-1){
//                System.out.print((char)len);
//                wt.write(len);
//            }
            char  []  chrs = new char[20];
//            while( (len = rd.read(chrs))!=-1){
//                System.out.print(String.valueOf(chrs));
//                wt.write(chrs);
//            }
//            rd.read(chrs,10,8);
//            System.out.println(String.valueOf(chrs));

            BufferedReader  br = new BufferedReader(rd);
            BufferedWriter  bw = new BufferedWriter(wt);
//            System.out.println((char)br.read());
            String line="";
            while((line =  br.readLine())!=null){
                System.out.println(line);
                wt.write(line+"\r\n");

            }
            br.close();
            rd.close();
            wt.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
